package com.fita.admin.dao;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.fita.entity.data.ExchangeRate;

import java.util.Date;
import java.util.List;

/**
 * 汇率
 * 
 * @author cuteHU
 *
 */
@Dao("hibernate")
public interface CurrencyDao {

    /**
     * @return
     */
    @Query("SELECT COUNT(*) FROM ExchangeRate")
    int count();

    /**
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM ExchangeRate ORDER BY effectiveTime DESC")
    List<ExchangeRate> listHistory(@Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);

    /**
     * @param currencyCode
     * @return
     */
    @Query("FROM ExchangeRate WHERE currencyCode =:currencyCode")
    List<ExchangeRate> listByCode(@Variable("currencyCode") String currencyCode);
    
    /**
     * 
     * @param code
     * @return
     */
    @Query("FROM ExchangeRate WHERE currencyCode =:code")
    public ExchangeRate load(@Variable("code") String code);

    /**
     * @return
     */
    @Query("SELECT DISTINCT(currencyCode) FROM ExchangeRate")
	List<String> listAllCurrencyCode();

	/**
	 * 获取最近生效的汇率
	 * @param currencyCode
	 * @param now
	 * @return
	 */
    @Query("FROM ExchangeRate WHERE currencyCode =:currencyCode AND effectiveTime <= :now ORDER BY effectiveTime DESC")
	ExchangeRate loadCurrentRate(@Variable("currencyCode") String currencyCode, @Variable("now") Date now);

}
